import './public-path';
import Vue from 'vue';
import VueRouter from 'vue-router';
import App from './App.vue';
// import routes from './router';
Vue.use(VueRouter)

// 解决重复导航报错问题
// 获取原型对象push函数
const VueRouterPush = VueRouter.prototype.push
// 修改原型对象中的push函数
VueRouter.prototype.push = function push (to) {
  return VueRouterPush.call(this, to).catch(err => err)
}
Vue.config.productionTip = false;
let router = null;
let instance = null;
function render(props = {}) {
  const { container } = props;
  router = new VueRouter({
    base: window.__POWERED_BY_QIANKUN__ ? '/app-vue/' : '/',
    mode: 'history',
    routes:[
      { path: '/demo1', component: ()=>  import("./views/app1-demo1.vue") },
      { path: '/demo2', component: ()=>  import("./views/app1-demo2.vue" ) }
    
    ],
  });

  instance = new Vue({
    router,
    render: (h) => h(App),
  }).$mount(container ? container.querySelector('#app') : '#app');
}

// 独立运行时
if (!window.__POWERED_BY_QIANKUN__) {
  console.log('9999999999999');
  render();
}

export async function bootstrap() {
  console.log('[vue] vue app bootstraped');
}
export async function mount(props) {
  console.log('[vue] props from main framework', props);
  render(props);
}
export async function unmount() {
  instance.$destroy();
  instance.$el.innerHTML = '';
  instance = null;
  router = null;
}